type t =
    {
      red : int;
      green : int;
      blue : int;
    }

let create _ =
  let x = {red = 0; green = 0 ; blue = 0} in
    x

let init r g b =
  let x = {red = r; green = g; blue = b} in
    x

let print x =
  Printf.printf "%i;%i;%i" x.red x.green x.blue

let get x = (x.red, x.green, x.blue)

let average x = (x.red + x.green + x.blue) / 3

let aver lst =
  let (r, v, b) = (ref 0, ref 0, ref 0) in
  let cpt = ref 0 in
  let rec disper = function
      [] -> ()
    | e::l ->
	cpt := !cpt + 1;
	r := e.red + !r;
	v := e.green + !v;
	b := e.blue + !b;
	disper l
  in
    disper lst;
    r := !r / !cpt;
    b := !b / !cpt;
    v := !v / !cpt;
    {red = !r; green = !v; blue = !b}

